home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
SAT 2.3.8
/
Demos
/
StepPlatform Demo ƒ
/
sHMovPlatform.c
< prev
next >
Wrap
Text File
|
1996-05-11
|
3KB
|
111 lines
/*****************************************
* Platform sprite, moveable version, not faceless *
/****************************************/
#include"SAT.h"
#include "myPlatform.h"
#ifndef abs
#define abs(x) (x>0?x:-x)
#endif
/*************** In platformSAT.h *****************\
* #define MaxV(me) (*(MovPlatP)me->appPtr).MaxV
* #define MinV(me) (*(MovPlatP)me->appPtr).MinV
*
* typedef struct {
* short MaxV,MinV;
* short MaxX,MinX;
* short filled; //unused
* } MovPlatRec,*MovPlatP;
*********************************************/
extern FacePtr platFace; /* Global from sMovPlatform.c */
void InitHMovPlatform()
{
}
pascal void SetupHMovPlatform(SpritePtr me)
{
Rect r;
PolyHandle pol;
me->speed.h = -1 + SATRand(2) * 2;
me->face = platFace;
me->appPtr = NewPtr(sizeof(MovPlatRec));
if (me->appPtr) {
(*(MovPlatP)me->appPtr).MaxH =me->position.h;
(*(MovPlatP)me->appPtr).MinH =me->kind;
}
SetRect(&(me->hotRect), 0, 3, 60, 20);
me->task = &HandleHMovPlatform;
me->hitTask = (void *) &HitHMovPlatform;
}
pascal void HandleHMovPlatform(SpritePtr me)
{
me->position.h = me->position.h + me->speed.h;
if(me->position.h < MinH(me)) me->speed.h = abs(me->speed.h);
if(me->position.h > MaxH(me)) me->speed.h = -abs(me->speed.h);
if(me->speed.h == 0){
if(me->position.h > (MaxH(me)-MinH(me)) / 2)
me->speed.h = -abs(me->speed.h);
else
me->speed.h = abs(me->speed.h);
}
me->layer = -me->position.v;
}
pascal void HitHMovPlatform(SpritePtr me, PlSpritePtr him)
{
int mini, i, min;
int diff[5];
if (him->task == HandleMovPlatform) {
SATReportStr("\pThere Has been a collotion between HmovPlatform and MovPlatform you shpuld fix that");
}
if(him->task == (void *) HandlePlayerSprite) {
diff[1] = -me->hotRect2.top + (him->hotRect2.bottom); /* TtoB */
diff[2] = -him->hotRect2.top + (me->hotRect2.bottom); /* BtoT */
diff[3] = -me->hotRect2.left + (him->hotRect2.right); /* LtoR */
diff[4] = -him->hotRect2.left + (me->hotRect2.right); /* RtoL */
mini = 0;
min = 10000;
for(i = 1; i <= 4; i++)
if(min > diff[i]){
min = diff[i];
mini = i;
}
switch(mini){
case 1: /*floor*/
him->action = StandOnHMovPlatform;
him->speed.h = me->speed.h;
him->position.v = him->position.v - diff[1] + 1;
him->position.h = him->position.h + me->speed.h;
if(him->speed.v > 0)
him->speed.v = 0;
break;
case 2: /* ceiling */
him->position.v = him->position.v + diff[2] + 1;
if(him->speed.v < 0)
him->speed.v = -him->speed.v;
break;
case 3: /*left*/
him->position.h = him->position.h - diff[3] - 1;
if (him->speed.h > 0)
him->speed.h = -him->speed.h;
break;
case 4: /*right*/
him->position.h = him->position.h + diff[4] + 1;
if (him->speed.h < 0)
him->speed.h = -him->speed.h;
break;
} /* switch */
} /* if */
}